package com.shadowtorcher.stdisk.logic;

import java.sql.SQLException;
import java.util.List;

import com.shadowtorcher.soulknife.SoulKnifeDB;
import com.shadowtorcher.soulknife.exception.BeanConfigErrorException;
import com.shadowtorcher.stdisk.bean.CommentBean;
import com.shadowtorcher.stdisk.bean.SharedFileBean;

public class Comment {
	private String comment;
	private String sharedFileID;
	//往数据库中插入comment
	public void insertComment(String comment,String sharedFileID){
		this.comment=comment;
		this.sharedFileID=sharedFileID;
		CommentBean commentbean=new CommentBean();
		commentbean.setComment(comment);
		commentbean.setSharedFileID(sharedFileID);
		try {
			commentbean.save();
		} catch (BeanConfigErrorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	//从数据库中读取comment
	public CommentBean getComment(String sharedFileID){
		this.sharedFileID=sharedFileID;
		CommentBean commentbean=new CommentBean();
		List<CommentBean> list;
		try {
			list = SoulKnifeDB.selectWhere("SharedFileID =?", sharedFileID).setClass(CommentBean.class);
			commentbean=list.get(0);
		
		} catch (BeanConfigErrorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return commentbean;		
		
	}
}
